home *** CD-ROM | disk | FTP | other *** search
- #include "QD3DtoQTVR.h"
- #include "extern.h"
- #include "draw.h"
- #include "file.h"
- #include "myMovies.h"
- #include "lights.h"
-
-
- OSErr MyOpenFile(FSSpec *theFile, DocumentPtr theDocument)
-
- { OSErr result;
- short refNum;
- FInfo fndrInfo ;
-
- FSpGetFInfo( theFile, &fndrInfo ) ;
-
- // Open file
- if ((result = FSpOpenDF(theFile, fsRdWrPerm, &refNum)) != noErr)
- return(result);
-
- // Assign file info to document
- theDocument->fRefNum = refNum;
- theDocument->theFileSpec = *theFile;
-
- // Set cursor and read model file
- SetCursor(*GetCursor(watchCursor));
- result = MyReadDocumentFile( theDocument);
-
- // Show window w/ title and reset cursor
- SetWTitle((WindowPtr)theDocument->theWindow, theFile->name);
- ShowWindow((WindowPtr)theDocument->theWindow);
- SetCursor(&qd.arrow);
-
- return(result);
- }
-
-
- OSErr MyReadDocumentFile(DocumentPtr theDocument)
- {
- TQ3StorageObject storage;
- TQ3FileObject fd;
- TQ3Object objects = nil;
- TQ3Status status;
-
- // create new storage and file objects
- storage = Q3MacintoshStorage_New( theDocument->fRefNum );
- if (storage == nil)
- goto bail;
- fd = Q3File_New();
- if (fd == nil)
- goto bail;
-
- // associate the storage with the file
- Q3File_SetStorage(fd, storage);
- Q3Object_Dispose(storage);
-
- // read the drawable objects from the file object into a new group
- status = MyReadScene(fd, theDocument);
- if (status == kQ3Failure)
- goto bail;
-
- Q3Object_Dispose(fd);
-
- return(noErr);
-
- bail:
- Q3Object_Dispose(fd);
-
- return(fnOpnErr);
- }
-
- TQ3Status MyReadScene(TQ3FileObject file, DocumentPtr theDocument)
- {
- TQ3Object object = NULL;
- TQ3Boolean isEOF;
- TQ3Boolean isOpen;
- TQ3Error firstError;
- TQ3ViewObject view;
- TQ3Object model;
- TQ3GroupObject lightGroup = NULL;
-
- SetCursor(*GetCursor(watchCursor));
-
- // Create new model and get view
- model = Q3DisplayGroup_New();
- if (!model)
- goto bail;
- theDocument->documentGroup = model;
- view = theDocument->theView;
-
- // Open file for reading
- if (Q3File_OpenRead(file, NULL) != kQ3Success)
- goto bail;
-
- // Collect all drawable objects (into model) and any lights (into lightgroup)
- while ((isEOF = Q3File_IsEndOfFile(file)) == kQ3False) {
- object = Q3File_ReadObject(file);
-
- // if we got an error reading, then bail
- if (Q3Error_Get(&firstError))
- goto bail;
-
- // if object read is not NULL then process object
- if (object != NULL) {
- if (Q3Object_IsDrawable(object))
- Q3Group_AddObject(model, object);
-
- if (Q3Object_IsType(object, kQ3SharedTypeViewHints))
- if (view)
- Q3ViewHints_GetLightGroup((TQ3ViewHintsObject)object, &lightGroup);
-
- Q3Object_Dispose(object);
- }
- }
-
- // if didn't reach end of file properly, then bail
- if (isEOF == kQ3False)
- goto bail;
-
- // Add lights found to view if found. Otherwise create default ones.
- if (lightGroup) {
- Q3View_SetLightGroup(view, lightGroup);
- Q3Object_Dispose(lightGroup);
- }
- else
- MyNewLights(theDocument);
-
- Q3File_Close(file);
-
- SetCursor(&qd.arrow);
- return kQ3Success;
-
- bail:
- Q3File_IsOpen(file, &isOpen);
- if (isOpen == kQ3True)
- Q3File_Close(file);
-
- if (object != NULL)
- Q3Object_Dispose(object);
-
- if (model != NULL) {
- Q3Object_Dispose(model);
- model = theDocument->documentGroup = NULL;
- }
-
- if (lightGroup != NULL)
- Q3Object_Dispose(lightGroup);
-
- SetCursor(&qd.arrow);
-
- return kQ3Failure;
- }
-
-
-
-
-